import java.net.InetAddress;
import java.net.ServerSocket;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.server.TThreadPoolServer.Args;
import org.apache.thrift.transport.TServerSocket;

import thriftGenerated.myService;



/**
 * Created by dengpan on 2016/12/3.
 */
public class HelloServerDemo {
    public void startServer() {
        try {
            //指定地址
            InetAddress addr = InetAddress.getByName("0.0.0.0");
            ServerSocket sock = new ServerSocket(1234, 50, addr);
            TServerSocket serverTransport = new TServerSocket(sock);

/*

            //简单的可以指定为
            TServerSocket serverTransport = new TServerSocket(1234);

*/

            myService.Processor process = new myService.Processor(new MyServiceImpl());
            TBinaryProtocol.Factory portFactory = new TBinaryProtocol.Factory(true, true);

            Args args = new Args(serverTransport);
            args.processor(process);
            args.protocolFactory(portFactory);

            TServer server = new TThreadPoolServer(args);
            server.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        System.out.println("start server....");
        HelloServerDemo server = new HelloServerDemo();
        server.startServer();
    }
}
